#include "Persister.h"

Persister::Persister() {
}

Persister::~Persister() {
}

bool Persister::save(string taskId) {

	TEST_ST st1;
	memset(&st1, 0, sizeof(TEST_ST));

	SharedContext sharedContext1("TEST_ST1", sizeof(TEST_ST));
	sharedContext1.get(&st1);
	if (SHRT_MAX <= st1.cnt)
		st1.cnt = 0;

	Logger logg = Logger::getLogger(taskId);
	if (logg.isDebugEnabled()) {
		std::stringstream ss;
		ss << "Persister::save START " << st1.cnt;
		logg.debug(ss.str());
	}

	cout << "after set st1 " << st1.user << endl;

	strncpy(&(st1.user[0]), "TEST_USR1", 9);
	st1.cnt = st1.cnt + 1;
	sharedContext1.set(&st1);
	sharedContext1.end();

	SharedRecord sharedRecord1("TEST_SR1", sizeof(TEST_ST), 10, true);
	TEST_ST st2;
	sharedRecord1.get(&st2, 3, 1);
	cout << "after get st2 " << st2.cnt << endl;
	if (SHRT_MAX <= st2.cnt)
		st2.cnt = 0;
	st2.cnt = st2.cnt + 1;
	sharedRecord1.set(&st2, 3, 1);
	sharedRecord1.end();

	return true;
}

